package com.rickpan.service;

import com.rickpan.entity.TeamActivityLog;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 团队活动日志服务接口
 * 
 * @author RickPan Team
 * @since 2024-01-15
 */
public interface TeamActivityLogService {

    /**
     * 记录活动日志
     */
    TeamActivityLog logActivity(Long teamId, Long userId, TeamActivityLog.ActionType actionType,
                               TeamActivityLog.TargetType targetType, Long targetId, 
                               String targetTitle, String description);

    /**
     * 记录活动日志（带元数据）
     */
    TeamActivityLog logActivity(Long teamId, Long userId, TeamActivityLog.ActionType actionType,
                               TeamActivityLog.TargetType targetType, Long targetId, 
                               String targetTitle, String description, String metadata);

    /**
     * 根据团队ID查找活动日志列表
     */
    List<TeamActivityLog> findActivitiesByTeam(Long teamId);

    /**
     * 根据团队ID查找活动日志列表（分页）
     */
    Page<TeamActivityLog> findActivitiesByTeam(Long teamId, Pageable pageable);

    /**
     * 根据用户ID查找活动日志列表
     */
    List<TeamActivityLog> findActivitiesByUser(Long userId);

    /**
     * 根据团队ID和用户ID查找活动日志列表
     */
    List<TeamActivityLog> findActivitiesByTeamAndUser(Long teamId, Long userId);

    /**
     * 根据团队ID和操作类型查找活动日志列表
     */
    List<TeamActivityLog> findActivitiesByTeamAndActionType(Long teamId, TeamActivityLog.ActionType actionType);

    /**
     * 根据团队ID和目标类型查找活动日志列表
     */
    List<TeamActivityLog> findActivitiesByTeamAndTargetType(Long teamId, TeamActivityLog.TargetType targetType);

    /**
     * 根据团队ID和目标ID查找活动日志列表
     */
    List<TeamActivityLog> findActivitiesByTeamAndTarget(Long teamId, TeamActivityLog.TargetType targetType, Long targetId);

    /**
     * 根据时间范围查找活动日志
     */
    List<TeamActivityLog> findActivitiesByDateRange(Long teamId, LocalDateTime startDate, LocalDateTime endDate);

    /**
     * 查找今日活动日志
     */
    List<TeamActivityLog> findTodayActivities(Long teamId);

    /**
     * 查找本周活动日志
     */
    List<TeamActivityLog> findWeekActivities(Long teamId);

    /**
     * 查找本月活动日志
     */
    List<TeamActivityLog> findMonthActivities(Long teamId);

    /**
     * 搜索活动日志
     */
    List<TeamActivityLog> searchActivities(Long teamId, String keyword);

    /**
     * 搜索活动日志（分页）
     */
    Page<TeamActivityLog> searchActivities(Long teamId, String keyword, Pageable pageable);

    /**
     * 获取活动统计信息
     */
    ActivityStatistics getActivityStatistics(Long teamId);

    // 便捷方法：项目相关活动记录
    void logProjectCreate(Long teamId, Long userId, Long projectId, String projectName);
    void logProjectUpdate(Long teamId, Long userId, Long projectId, String projectName);
    void logProjectDelete(Long teamId, Long userId, Long projectId, String projectName);
    void logProjectStatusChange(Long teamId, Long userId, Long projectId, String projectName, String oldStatus, String newStatus);
    void logProjectManagerAssign(Long teamId, Long userId, Long projectId, String projectName, String managerName);

    // 便捷方法：任务相关活动记录
    void logTaskCreate(Long teamId, Long userId, Long taskId, String taskTitle);
    void logTaskUpdate(Long teamId, Long userId, Long taskId, String taskTitle);
    void logTaskDelete(Long teamId, Long userId, Long taskId, String taskTitle);
    void logTaskStatusChange(Long teamId, Long userId, Long taskId, String taskTitle, String oldStatus, String newStatus);
    void logTaskAssign(Long teamId, Long userId, Long taskId, String taskTitle, String assigneeName);
    void logTaskComplete(Long teamId, Long userId, Long taskId, String taskTitle);

    // 便捷方法：公告相关活动记录
    void logAnnouncementCreate(Long teamId, Long userId, Long announcementId, String announcementTitle);
    void logAnnouncementUpdate(Long teamId, Long userId, Long announcementId, String announcementTitle);
    void logAnnouncementDelete(Long teamId, Long userId, Long announcementId, String announcementTitle);
    void logAnnouncementPin(Long teamId, Long userId, Long announcementId, String announcementTitle);
    void logAnnouncementUnpin(Long teamId, Long userId, Long announcementId, String announcementTitle);

    /**
     * 活动统计信息类
     */
    class ActivityStatistics {
        private long totalActivities;
        private long todayActivities;
        private long weekActivities;
        private long monthActivities;
        private long projectActivities;
        private long taskActivities;
        private long announcementActivities;

        // 构造函数
        public ActivityStatistics() {}

        public ActivityStatistics(long totalActivities, long todayActivities, long weekActivities,
                                long monthActivities, long projectActivities, long taskActivities,
                                long announcementActivities) {
            this.totalActivities = totalActivities;
            this.todayActivities = todayActivities;
            this.weekActivities = weekActivities;
            this.monthActivities = monthActivities;
            this.projectActivities = projectActivities;
            this.taskActivities = taskActivities;
            this.announcementActivities = announcementActivities;
        }

        // Getter 和 Setter
        public long getTotalActivities() { return totalActivities; }
        public void setTotalActivities(long totalActivities) { this.totalActivities = totalActivities; }

        public long getTodayActivities() { return todayActivities; }
        public void setTodayActivities(long todayActivities) { this.todayActivities = todayActivities; }

        public long getWeekActivities() { return weekActivities; }
        public void setWeekActivities(long weekActivities) { this.weekActivities = weekActivities; }

        public long getMonthActivities() { return monthActivities; }
        public void setMonthActivities(long monthActivities) { this.monthActivities = monthActivities; }

        public long getProjectActivities() { return projectActivities; }
        public void setProjectActivities(long projectActivities) { this.projectActivities = projectActivities; }

        public long getTaskActivities() { return taskActivities; }
        public void setTaskActivities(long taskActivities) { this.taskActivities = taskActivities; }

        public long getAnnouncementActivities() { return announcementActivities; }
        public void setAnnouncementActivities(long announcementActivities) { this.announcementActivities = announcementActivities; }
    }
}
